import java.awt.Image;

import javax.swing.ImageIcon;


public class Bullet
{
	int x, dx, y, dy;
	Image img;
	double direction;
	
	public Bullet(int x, int y, double x2, double y2)
	{
		img = new ImageIcon("images/bullet.gif").getImage();
		this.x = x;
		this.y = y;
		
		setDirection(x2, y2);
	}
	
	public void move()
	{
		x = x + dx;
		y = y + dy;
	}
	
	public int getX()
	{
		return x;
	}
	public int getY()
	{
		return y;
	}
	public Image getImage()
	{
		return img;
	}
	
	public void setXVelocity(int dx)
	{
		this.dx = dx;
	}
	public void setYVelocity(int dy)
	{
		this.dy = dy;
	}
	
	public void setDirection(double xdir, double ydir)
	{
		direction = Math.atan2(x-xdir, y-ydir);
		
		System.out.println("dir=" + Math.toDegrees(direction));
		
		int dir = (int)Math.toDegrees(direction);
		
		if(dir <= 30 && dir > -30)
		{
			setXVelocity(0);
			setYVelocity(-1);
		}
		if(dir >= 30 && dir < 60)
		{
			setXVelocity(-1);
			setYVelocity(-1);
		}
		if(dir >= 60 && dir < 90)
		{
			setXVelocity(-1);
			setYVelocity(0);
		}
		if(dir >= 90 && dir < 120)
		{
			setXVelocity(-1);
			setYVelocity(1);
		}
		if(dir >= 120 && dir <= 180)
		{
			setXVelocity(0);
			setYVelocity(1);
		}
		
		
		if(dir <= -30 && dir > -60)
		{
			setXVelocity(1);
			setYVelocity(-1);
		}
		if(dir <= -60 && dir > -90)
		{
			setXVelocity(1);
			setYVelocity(0);
		}
		if(dir <= -90 && dir > -120)
		{
			setXVelocity(1);
			setYVelocity(1);
		}
		if(dir <= -120 && dir >= -180)
		{
			setXVelocity(0);
			setYVelocity(1);
		}
		
	}
	public double getDirection()
	{
		return direction;
	}
}
